package com.property.cleaning.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.property.cleaning.entity.Cleaner;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 保洁人员Mapper接口
 * 
 * @author Property Cleaning System
 */
@Mapper
public interface CleanerMapper extends BaseMapper<Cleaner> {

    /**
     * 分页查询保洁人员列表
     */
    @Select("SELECT c.*, u.real_name, u.username, u.phone FROM cleaners c " +
            "LEFT JOIN users u ON c.user_id = u.id " +
            "WHERE u.status = 1 " +
            "ORDER BY c.created_at DESC")
    IPage<Cleaner> findCleanerPage(Page<Cleaner> page);

    /**
     * 根据用户ID查询保洁人员信息
     */
    @Select("SELECT c.*, u.real_name, u.username, u.phone FROM cleaners c " +
            "LEFT JOIN users u ON c.user_id = u.id " +
            "WHERE c.user_id = #{userId}")
    Cleaner findByUserId(@Param("userId") Long userId);

    /**
     * 根据员工编号查询
     */
    @Select("SELECT c.*, u.real_name, u.username, u.phone FROM cleaners c " +
            "LEFT JOIN users u ON c.user_id = u.id " +
            "WHERE c.employee_no = #{employeeNo}")
    Cleaner findByEmployeeNo(@Param("employeeNo") String employeeNo);

    /**
     * 查询在岗保洁人员
     */
    @Select("SELECT c.*, u.real_name, u.username, u.phone FROM cleaners c " +
            "LEFT JOIN users u ON c.user_id = u.id " +
            "WHERE c.current_status = 1 AND u.status = 1 " +
            "ORDER BY c.skill_level DESC, c.work_experience DESC")
    IPage<Cleaner> findActiveCleaners(Page<Cleaner> page);
}